! function (e) {
    function o() {
        var o = e.ajaxSettings.xhr;
        e.ajaxSetup({
            xhr: function () {
                var e = o(),
                    r = this;
                return e && "object" == typeof e.upload && void 0 !== r.progressUpload && e.upload.addEventListener("progress", function (e) {
                    r.progressUpload(e)
                }, !1), e
            }
        })
    }
    o(), e.extend(!0, e.trumbowyg, {
        langs: {
            en: {
                upload: "Upload",
                file: "File",
                uploadError: "Error"
            },
            fr: {
                upload: "Envoi",
                file: "Fichier",
                uploadError: "Erreur"
            }
        },
        upload: {
            serverPath: "./trumbowyg/plugins/upload/trumbowyg.upload.php"
        },
        opts: {
            btnsDef: {
                upload: {
                    func: function (o, r) {
                        var a, t = r.o.prefix,
                            n = r.openModalInsert(r.lang.upload, {
                                file: {
                                    type: "file",
                                    required: !0
                                },
                                alt: {
                                    label: "description"
                                }
                            }, function () {
                                var o = new FormData;
                                o.append("fileToUpload", a), 0 == e("." + t + "progress", n).length && e("." + t + "modal-title", n).after(e("<div/>", {
                                    "class": t + "progress"
                                }).append(e("<div/>", {
                                    "class": t + "progress-bar"
                                }))), e.ajax({
                                    url: e.trumbowyg.upload.serverPath,
                                    type: "POST",
                                    data: o,
                                    cache: !1,
                                    dataType: "json",
                                    processData: !1,
                                    contentType: !1,
                                    progressUpload: function (o) {
                                        e("." + t + "progress-bar").stop().animate({
                                            width: Math.round(100 * o.loaded / o.total) + "%"
                                        }, 200)
                                    },
                                    success: function (o) {
                                        "uploadSuccess" == o.message ? (r.execCommand("insertImage", o.file), setTimeout(function () {
                                            r.closeModal()
                                        }, 250)) : r.addErrorOnModalField(e("input[type=file]", n), r.lang[o.message])
                                    },
                                    error: function () {
                                        r.addErrorOnModalField(e("input[type=file]", n), r.lang.uploadError)
                                    }
                                })
                            });
                        e("input[type=file]").on("change", function (e) {
                            a = e.target.files[0]
                        })
                    }
                }
            }
        }
    })
}(jQuery);
